package com.toocms.jinjuhang.ui.mine.payment.bank.code;

import android.app.Application;

import androidx.annotation.NonNull;

import com.toocms.jinjuhang.config.Constants;
import com.toocms.jinjuhang.config.UserRepository;
import com.toocms.tab.base.BaseViewModel;
import com.toocms.tab.binding.command.BindingCommand;
import com.toocms.tab.bus.Messenger;
import com.toocms.tab.network.ApiTool;

/**
 * @Description:
 * @Author: Zero
 * @CreateDate: 2023/5/19 11:37
 */
public class CodeViewModel extends BaseViewModel {

    public String signid, trade_no, order_sn;

    public CodeViewModel(@NonNull Application application) {
        super(application);
    }

    public BindingCommand dismiss = new BindingCommand(this::finishFragment);

    public void signConfirm(String code) {
        ApiTool.post("/Center/signConfirm")
                .add("member_id", UserRepository.INSTANCE.getUser().getMember_id())
                .add("signid", signid)
                .add("verify", code)
                .asTooCMSResponse(String.class)
                .withViewModel(this)
                .request(s -> {
                    showToast(s);
                    Messenger.getDefault().sendNoMsg(Constants.MessengerToken.TOKEN_CODE);
                    finishFragment();
                });
    }

    public void ys_protocol_pay_confirm(String code) {
        ApiTool.post("/OrderPay/ys_protocol_pay_confirm")
                .add("trade_no", trade_no)
                .add("verify", code)
                .add("signid", signid)
                .add("order_sn", order_sn)
                .add("member_id", UserRepository.INSTANCE.getUser().getMember_id())
                .asTooCMSResponse(String.class)
                .withViewModel(this)
                .request(s -> {
                    Messenger.getDefault().sendNoMsg(Constants.MessengerToken.TOKEN_CODE2);
                    finishFragment();
                });
    }
}
